﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace YunZiChanApi.Yunbo
{
    /// <summary>
    /// basic验证
    /// </summary>
    public class BaseFilters : BaseController, IAuthorizationFilter
    {
       

        public void OnAuthorization(AuthorizationFilterContext context)
        {
            //// 标记为[AllowAnonymous] 的控制器可直接跳过拦截器
            //if (context.Filters.Contains(new AllowAnonymous()))
            //{
            //    return;
            //}
            //// 标记为[LoginAuthorzation] 的控制器可直接跳过拦截器
            //if (context.Filters.Contains(new LoginAuthorzation()))
            //{
            //    return;
            //}
            //var authorization = context.HttpContext.Request.Headers["Authorization"];
            ////验证请求头是否存在token
            //if (string.IsNullOrEmpty(authorization))
            //{
            //    context.Result = Error("缺少Authorization请求头参数");
            //    return;
            //}
            //if (authorization.Contains("bearer"))
            //{
            //    context.Result = Error("参数中缺少bearer 字符");
            //    return;
            //}

        }
    }
    /// <summary>
    /// 允许匿名请求
    /// </summary>
    public class AllowAnonymous : Attribute, IFilterMetadata
    {

    }
    /// <summary>
    /// 登入授权请求
    /// </summary>
    public class LoginAuthorzation : Attribute, IFilterMetadata
    {

    }

}